package constellation.adapter;

import java.util.List;

import android.content.Context;
import android.graphics.Bitmap;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.myapplication.R;

import constellation.util.AssetsUtil;
import constellation.util.StartInfo;

public class StartItemGridviewAdapter extends BaseAdapter {

    List<StartInfo.StarinfoBean> list;

    private Context context;
    private LayoutInflater layoutInflater;

    public StartItemGridviewAdapter(Context context,List<StartInfo.StarinfoBean> list) {
        this.list=list;
        this.context = context;
        this.layoutInflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = layoutInflater.inflate(R.layout.start_item_gridview, null);
            holder=new ViewHolder(convertView);
            convertView.setTag(holder);
        }else {
            holder=(ViewHolder)convertView.getTag();
        }
        StartInfo.StarinfoBean bean=list.get(position);
        holder.startItemText.setText(bean.getName());
        String logoname=bean.getLogoname();
        String filename="xzlogo/"+logoname+".png";
        Bitmap bitmap= AssetsUtil.getBitmapByAssets(context,filename);
        holder.startItemImage.setImageBitmap(bitmap);
        return convertView;
    }


    protected class ViewHolder {
        private ImageView startItemImage;
    private TextView startItemText;

        public ViewHolder(View view) {
            startItemImage =  view.findViewById(R.id.start_item_image);
            startItemText = view.findViewById(R.id.start_item_text);
        }
    }
}
